package com.itheima.demo001;

public class IdealTest {
    public static void main(String[] args) {
        //1.创建一个数组
        Ideal[] arr = new Ideal[4];

        //2.创建理想型的对象
        Ideal i1 = new Ideal("花满楼",25,"男","饮酒作乐","侠义洒脱公子");
        Ideal i2 = new Ideal("贺寄傲",19,"女","排兵布阵","驰骋沙场女将军");
        Ideal i3 = new Ideal("荆池鱼",29,"男","路见不平","江湖第一侠客");
        Ideal i4 = new Ideal("顾北",21,"男","研究医术","悬壶济世神医");

        //3.把理想型的对象，存入到数组中
        arr[0] = i1;
        arr[1] = i2;
        arr[2] = i3;
        arr[3] = i4;

        //4.获取理想型的平均年龄
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            Ideal ideal = arr[i];
            sum = sum + ideal.getAge();
        }

        //5.求平均年龄
        int avg = sum / arr.length;

        System.out.println(avg);//23(23.5)

        //6.统计比平均值小的理想型
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            Ideal ideal = arr[i];
            if(ideal.getAge() < avg){
                System.out.println(ideal.getName() + ", " + ideal.getAge() + ", " + ideal.getGender() + ", " + ideal.getHobby() + ", " + ideal.getType());
                count++;
                //贺寄傲, 19, 女, 排兵布阵, 驰骋沙场女将军
                //顾北, 21, 男, 研究医术, 悬壶济世神医
            }
        }
        System.out.println(count);//2

    }
}
